define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'hospital/index' + location.search,
                    add_url: 'hospital/add',
                    edit_url: 'hospital/edit',
                    del_url: 'hospital/del',
                    multi_url: 'hospital/multi',
                    import_url: 'hospital/import',
                    table: 'hospital',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'nicknames', title: __('Nicknames'), operate:false,formatter: Table.api.formatter.label},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status,searchList: {"0":__('Status 0'),"1":__('Status 1')}},
                        {field: 'admin_ids', title: __('账号管理'), operate:false,
                            table: table,
                            events: Table.api.events.operate,
                            buttons:[
                                {
                                    extend: 'data-area=["700px","500px"]',
                                    text: __('账号管理'),
                                    name: "problem",
                                    title: __('账号管理'),
                                    classname:'btn btn-dialog',
                                    url:'hospital/account',
                                }
                            ],
                            formatter: Table.api.formatter.buttons

                        },
                        /* {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        */{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        account: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
